home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5.2 / dcmds / C Samples / Vol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  5.2 KB  |  225 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Vol.c
  3.  
  4.     Contains:    A dcmd which dumps all volumes from the VCB queue.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglas
  9.  
  10.     Copyright:    © 1988,1993-1994 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <5>   11-Dec-94    JM3        Updated for new version 3 dcmd requirements.
  15.          <4>   24-Jan-94    JM3        EqualString is now in TextUtils.h with the Universal Interfaces.
  16.          <2>     9/10/93    DAL        Fixed volume-name matching to work again (was using
  17.                                     non-prototyped "EQUALSTRING" instead of EqualString).  Widened
  18.                                     the volume-name column.  Changed "VCB at" to "VCB addr" and made
  19.                                     it align for 32-bit addresses.
  20.  
  21.     Modification history:
  22.         29Nov88 sad        revised for new dcmd names.  display more info.
  23.          5Oct88 sad        written.
  24.  
  25.     The following MPW commands will build the dcmd and copy it to the
  26.     "Debugger Prefs" file in the System folder. The dcmd's name in
  27.     MacsBug will be the name of the file built by the Linker.
  28.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  29.     C Samples folder into this folder.
  30.  
  31.     C Put.c
  32.     C Vol.c
  33.     Link dcmdGlue.a.o Vol.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Vol
  34.     BuildDcmd Vol 1002
  35.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  36. */
  37.  
  38. #include <Types.h>
  39. #include <Memory.h>
  40. #include <OSUtils.h>
  41. #include <Files.h>
  42. #include <TextUtils.h>
  43.  
  44. #include "dcmd.h"
  45. #include "put.h"
  46.  
  47. #define VCBQHdr ((QHdrPtr)0x356)
  48.  
  49.  
  50. static void DrawHdr()
  51. {
  52. //                             1         2         3         4         5         6         7
  53. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  54.     dcmdDrawLine("\pvRef Vol                  Flg dRef Drive FSID #Blk BlkSiz #Files #Dirs  Blsd Dir VCB addr");
  55.  
  56. }
  57.  
  58.  
  59. static void DrawVCB(VCB* vcbp)
  60. {
  61.  
  62.     PutUHexWord(vcbp->vcbVRefNum);
  63.     PutSpace();
  64.     PutPStrTruncTo(vcbp->vcbVN,15+10);
  65.     PutSpace();
  66.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  67.     PutChar((vcbp->vcbAtrb & 0x8000) ? 'S' : 's');
  68.     PutChar((vcbp->vcbAtrb & 0x4000) ? 'H' : 'h');
  69.     PutSpace();
  70.     PutUHexWord(vcbp->vcbDRefNum);
  71.     PutSpace();
  72.     PutSpace();
  73.     PutUHexWord(vcbp->vcbDrvNum);
  74.     PutSpace();
  75.     PutUHexWord(vcbp->vcbFSID);
  76.     PutSpace();
  77.     PutUHexWord(vcbp->vcbNmAlBlks);
  78.     PutSpace();
  79.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47+10);
  80.     PutSpace();
  81.     PutUHexZTo(vcbp->vcbFilCnt,6,54+10);
  82.     PutSpace();
  83.     PutUHexZTo(vcbp->vcbDirCnt,6,61+10);
  84.     PutSpace();
  85.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70+10);
  86.     PutSpace();
  87.     PutUHexZTo((unsigned long)vcbp,8,77+10);
  88.     PutLine();
  89.  
  90. }
  91.  
  92.  
  93. // PrefixPStr
  94. //
  95. // Returns true if astr is equal to a prefix of bstr.
  96. // astr must not be longer than 31 characters.
  97.  
  98. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  99. {
  100.  
  101.     char newstr[32];
  102.     int alen = *astr;
  103.     int blen = *bstr;
  104.  
  105.     if (alen <= blen)
  106.     {
  107.         BlockMove(bstr+1,newstr+1,alen);
  108.         newstr[0] = alen;
  109.         return EqualString(astr,newstr,false,true);
  110.     }
  111.  
  112.     return false;    
  113.  
  114. }
  115.  
  116.  
  117.  
  118. pascal void CommandEntry(dcmdBlock* paramPtr)
  119. {
  120.  
  121.     static const char usageStr[] = "\p[vRefNum|drvNum|\"vol name\"]";
  122.  
  123.     switch (paramPtr->request)
  124.     {
  125.         case dcmdInit:
  126.             break;
  127.  
  128.         case dcmdHelp:
  129.             dcmdDrawLine("\pDisplays volume information for the given vrefnum, volume name or all");
  130.             dcmdDrawLine("\pmounted volumes. Flags are D/d=Dirty, S/s=Software locked,");
  131.             dcmdDrawLine("\pH/h=Hardware locked.");
  132.             break;
  133.  
  134.         case dcmdGetInfo:
  135.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  136.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  137.             break;
  138.  
  139.         case dcmdDoIt:
  140.         {
  141.             Boolean    doOneVCB = false;
  142.             long    vref;
  143.             short    c;
  144.             Boolean    haveVolName = false;
  145.             Str255    volname;
  146.             VCB*    vcbp;
  147.             int        numvcbs = 0;
  148.             Boolean    foundOne = false;
  149.  
  150.             dcmdSwapWorlds();
  151.  
  152.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  153.  
  154.             // get low-memory values after dcmdSwapWorlds()
  155.             vcbp = (VCB*) (VCBQHdr->qHead);
  156.  
  157.             c = dcmdPeekAtNextChar();
  158.             if (c == '"' || c == '\'')
  159.             {
  160.                 haveVolName = true;
  161.                 (void) dcmdGetNextParameter(volname);
  162.             }
  163.             else
  164.                 (void) dcmdGetNextExpression(&vref, &doOneVCB);
  165.  
  166.             if (doOneVCB)
  167.                 vref = (short) vref;
  168.  
  169.             while (vcbp)
  170.             {
  171.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  172.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  173.                     (!doOneVCB && !haveVolName))
  174.                 {
  175.                     numvcbs++;
  176.                     if (!foundOne)
  177.                     {
  178.                         DrawHdr();
  179.                         foundOne = true;
  180.                     }
  181.                     DrawVCB(vcbp);
  182.                 }
  183.                 if (paramPtr->aborted) break;
  184.                 if (vcbp->qLink == 0)
  185.                     if (vcbp != (VCB*)(VCBQHdr->qTail))
  186.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  187.                 vcbp = (VCB*)vcbp->qLink;
  188.             }
  189.             if (!paramPtr->aborted)
  190.                 if (haveVolName || doOneVCB)
  191.                 {
  192.                     if (!foundOne)
  193.                         if (haveVolName)
  194.                         {
  195.                             PutPStr("\pNo mounted volumes match \"");
  196.                             PutPStr(volname);
  197.                             PutChar('"');
  198.                             PutLine();
  199.                         }
  200.                         else
  201.                         {
  202.                             PutPStr("\pNo mounted volumes match ");
  203.                             PutUHexWord(vref);
  204.                             PutLine();
  205.                         }
  206.                 }
  207.                 else
  208.                 {
  209.                     PutUDec(numvcbs);
  210.                     PutPStr("\p VCBs");
  211.                     PutLine();
  212.                 }
  213.  
  214.             dcmdSwapWorlds();
  215.             break;
  216.         }
  217.  
  218.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  219.  
  220.         default:
  221.             break;
  222.     }
  223.  
  224. } // CommandEntry
  225.